package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.ContactNote;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class ContactNoteDao {
	DBHelp<ContactNote> db=new DBHelp<ContactNote>();
	
	public boolean addcontactnote(ContactNote c){
		String sql="insert into t_contactnote (id,content,createtime,t_contact_id,t_user_id) values (?,?,?,?,?)";
		return db.executeSQL(sql, c.getId(),c.getContent(),c.getCreatetime(),c.getContactid(),c.getUserid());
	}
	
	private class NoteRowMapper implements RowMapper<ContactNote>{

		public ContactNote mapRow(ResultSet rs) throws SQLException {
			ContactNote c=new ContactNote();
			c.setId(rs.getString("id"));
			c.setContent(rs.getString("content"));
			c.setCreatetime(rs.getString("createtime"));
			c.setContactid(rs.getString("t_contact_id"));
			c.setUserid(rs.getString("t_user_id"));
			
			return c;
		}
		
	}

	public List<ContactNote> findAll() {
		String sql="select id,content,createtime,t_contact_id,t_user_id from t_contactnote order by createtime DESC";
		return db.executeQueryForList(sql, new NoteRowMapper());
	}

	public List<ContactNote> findByConidAndUserid(String conid, String userid) {
		// TODO Auto-generated method stub
		String sql="select id,content,createtime,t_contact_id,t_user_id from t_contactnote where t_contact_id=? and t_user_id=? order by createtime DESC";
		return db.executeQueryForList(sql, new NoteRowMapper(),conid,userid);
	}
}
